#-*- Makefile -*-
#
# ${R_HOME}/src/library/tools/Makefile

srcdir = .
top_srcdir = ../../..

top_builddir = ../../..

include $(top_builddir)/Makeconf

pkg = tools

RSRC = `LC_COLLATE=C ls $(srcdir)/R/*.R`

ifdef USE_LLVM
  R_SYSTEM_ABI = "windows,clang,clang++,flang,flang"
else
  R_SYSTEM_ABI = "windows,gcc,g++,gfortran,gfortran"
endif

## We first use mkdesc2 (with date) to install the DESCRIPTION, then re-install
all:
	@$(ECHO) "building package '$(pkg)'"
	@$(MKINSTALLDIRS) $(top_builddir)/library/$(pkg)
	@$(MAKE) -f Makefile.win mkR1 mkdesc2 mksrc-win2
	@if ! test $(top_builddir)/library/$(pkg)/R/$(pkg) -nt all.R; then \
	  $(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg); \
	fi
	@$(MAKE) -f Makefile.win sysdata
	@$(ECHO) "tools:::.install_package_description('.', '"$(top_builddir)/library/${pkg}"')" | \
	  R_DEFAULT_PACKAGES=NULL $(R_EXE) > /dev/null

include $(top_srcdir)/share/make/basepkg.mk

## Note that R_COMPILER_SUPPRESS_ALL is now on by default
$(top_builddir)/library/$(pkg)/R/$(pkg).rdb: all.R $(top_srcdir)/share/licenses/license.db
	@$(ECHO) "byte-compiling package '$(pkg)'"
	@$(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg)
	@(cat $(srcdir)/R/makeLazyLoad.R; \
	  $(ECHO) "makeLazyLoading(\"$(pkg)\")") | \
	  _R_COMPILE_PKGS_=1 R_COMPILER_SUPPRESS_ALL=1 \
	  R_SYSTEM_ABI=$(R_SYSTEM_ABI) \
	  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) > /dev/null

Rsimple: mkR mkRsimple

Rlazy: mkR mkRsimple
	@$(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg)
	@(cat $(srcdir)/R/makeLazyLoad.R; \
	  $(ECHO) "makeLazyLoading(\"$(pkg)\")") | \
	  R_SYSTEM_ABI=$(R_SYSTEM_ABI) \
	  R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) > /dev/null

Rlazycomp: mkR mkRsimple mklazycomp
